package com.dashboard.dkmh;

import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.HashMap;

import com.lb.jwitter.connectDatabase.ConnectPDT;
import com.opensymphony.xwork2.Action;

public class ListBoMonOfKhoaAction {
	private String khoa;
	private ArrayList<HashMap<String, String>> listBoMon;
	
	
	public String getKhoa() {
		return khoa;
	}


	public void setKhoa(String khoa) {
		this.khoa = khoa;
	}


	public ArrayList<HashMap<String, String>> getListBoMon() {
		return listBoMon;
	}


	public void setListBoMon(ArrayList<HashMap<String, String>> listBoMon) {
		this.listBoMon = listBoMon;
	}


	public String execute() throws Exception
	{
		if(khoa==null||khoa.length()<1){
			return Action.ERROR;
		}
		ConnectPDT connectionOracle= new ConnectPDT();
		if(connectionOracle.getConnection()!=null){
			listBoMon=new ArrayList<HashMap<String, String>>();
			
			String query="select DISTINCT MA_BO_MON, TEN_BO_MON from PDT_WEB.DM_BO_MON where MA_KHOA='"+khoa+"'";
			HashMap<String,String> map;	
			ResultSet data=connectionOracle.getData(query);
			if(data!=null){
				while(data.next()){
					map = new HashMap<String,String>();
					String maBoMon=data.getString("MA_BO_MON");
					String tenBoMon=data.getString("TEN_BO_MON");
					map.put("maBoMon", maBoMon);
					map.put("tenBoMon", tenBoMon);
					listBoMon.add(map);
				}
			}
			
			
		}
		connectionOracle.closeConnection();
		return Action.SUCCESS;

	}
}
